﻿using System;
using UnityEngine;


namespace RStudio.UIFramwork
{
    /// <summary>
    /// 基类|UI
    /// </summary>
    /// 
    [SerializeField]
    public class UIBase : MonoBehaviour, IUIBaseBehaviour
    {
        #region UI 生命周期
        public virtual void CreateUI()
        {       
            this.OnUICreated?.Invoke(this);
        }
        public virtual void ActiveUI()
        {
            if (!IsStartUI)
            {
                StartUI();
                IsStartUI = true;
            }

            this.OnUIActived?.Invoke(this);
        }
        public virtual void StartUI()
        {
            this.InitComponent();
        }
        public virtual void DeActiveUI()
        {
            this.OnUIDeactived?.Invoke(this);
        }
        public virtual void DisposeUI()
        {
            this.OnUIDisposed?.Invoke(this);
        }
        #endregion

        #region UI 特性
        [HideInInspector, Tooltip("StartUI 周期控制")] public bool IsStartUI { get; private set; } = false;

        [Tooltip("UID")] public string UID;
        [HideInInspector, Tooltip("模块|区域阻挡")] public bool UseBlock = false;
        [HideInInspector, Tooltip("模块|区域退出")] public bool UseAreaQuit = false;
        [HideInInspector, Tooltip("模块|区域遮罩")] public bool UseMask = false;

        [HideInInspector, Tooltip("模块|作为单例")] public bool UseAsSingle = false;
        [HideInInspector, Tooltip("模块|关旧通知")] public bool UseClosePrevious = false;
        [HideInInspector, Tooltip("布局|使用四周")] public bool UseQuardRato = false;
        [HideInInspector, Tooltip("布局|标准居中")] public bool UseCentral = true;
        [HideInInspector, Tooltip("模块|关旧允许")] public bool CanBeClosed = false;
        [HideInInspector, Tooltip("模块|历史队列")] public bool CanBeRecord = false;

        [HideInInspector, Tooltip("模块|允许拖拽")] public bool CanDrag = false;
        [HideInInspector, Tooltip("模块|拖拽参数")] public UIDragSetting UIDragSetting;
        #endregion

        #region UI 事件
        [Tooltip("事件|页面创建时")] public event Action<UIBase> OnUICreated;
        [Tooltip("事件|页面激活时")] public event Action<UIBase> OnUIActived;
        [Tooltip("事件|页面禁用时")] public event Action<UIBase> OnUIDeactived;
        [Tooltip("事件|页面释放时")] public event Action<UIBase> OnUIDisposed;
        #endregion

        public virtual void InitComponent() { }
    }
}